$(function () {
    layui.use(['form', 'layer', 'jquery'],
        function () {
            let $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            //自定义验证规则
            form.verify({
                managerName: function (value) {
                    if (value.length < 4) {
                        return '昵称至少得4个字符啊';
                    }
                },
                pass: [/(.+){6,18}$/, '密码必须6到18位'],
                repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            //监听提交
            form.on('submit(add)',
                function (data) {
                    data.field._method = "put"
                    let res = request('http://localhost:8080/admin/manager/add', 'post', data.field)
                    if (res.code === 0) {
                        layer.alert("增加成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.alert("添加失败", {
                                icon: 7
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();
                            })
                    }
                    return false;
                });

        });
})